package com.djinfo.work.service.impl;

import com.djinfo.work.common.service.impl.BaseServiceImpl;
import com.djinfo.work.dao.impl.NoticeDaoImpl;
import com.djinfo.work.entity.SysNoticeEntity;
import com.djinfo.work.entity.SysNoticeDeptEntity;
import com.djinfo.work.service.NoticeDepartService;
import org.springframework.stereotype.Service;


/**
 *
 */
@Service("NoticeDepartService")
public class NoticeDepartServiceImpl extends BaseServiceImpl<SysNoticeDeptEntity,NoticeDaoImpl> implements NoticeDepartService {

	/**
	 * 批量删除,单个删除，公告的通知部门
	 * @param id
     */
	@Override
	public void delSomeData(String id) {
		try {
			String hql = "delete from SysNoticeDeptEntity where noticeDepartid='"+id+"'";
			this.delSome(hql);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * 更新公告的通知部门
	 * @param sysNoticeEntity
	 * @param nowTime
     * @param id
     */
	@Override
	public void updateDepart(SysNoticeEntity sysNoticeEntity, String nowTime, String id) {
		try {
			String[] depts = sysNoticeEntity.getReceiveObject().split(",");
			for(String d:depts){
                SysNoticeDeptEntity sysNoticeDeptEntity =new SysNoticeDeptEntity();
                sysNoticeDeptEntity.setNoticeDepartid(sysNoticeEntity.getId());
                sysNoticeDeptEntity.setDepartName(d);
                sysNoticeDeptEntity.setCreateTime(nowTime);
                sysNoticeDeptEntity.setUpdateTime(nowTime);
                sysNoticeDeptEntity.setCreateUser(id);
                sysNoticeDeptEntity.setUpdateUser(id);
                this.save(sysNoticeDeptEntity);
            }
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * 新增公告的通知部门
	 * @param sysNoticeEntity
	 * @param nowTime
     * @param id
     */
	@Override
	public void saveDepart(SysNoticeEntity sysNoticeEntity, String nowTime, String id) {
		try {
			String[] depts = sysNoticeEntity.getReceiveObject().split(",");
			for(int i=0;i<depts.length;i++){
                SysNoticeDeptEntity sysNoticeDeptEntity =new SysNoticeDeptEntity();
                sysNoticeDeptEntity.setNoticeDepartid(sysNoticeEntity.getId());
                sysNoticeDeptEntity.setDepartName(depts[i]);
                sysNoticeDeptEntity.setCreateTime(nowTime);
                sysNoticeDeptEntity.setUpdateTime(nowTime);
                sysNoticeDeptEntity.setCreateUser(id);
                sysNoticeDeptEntity.setUpdateUser(id);
                this.save(sysNoticeDeptEntity);
            }
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
